from pyparsing import Word,alphas,OneOrMore,Combine,Literal

import Commands

go = Literal("go")('verb')
look = Literal("look")('verb')

identifier = Combine(OneOrMore(Word(alphas)), joinString=' ', adjacent=False)('identifier')

movement = go + identifier
parser = movement |look

def dispatch(string):
   #Try and parse the expression, this may fail due to not being in the grammar.
   try:
      parsedict = parser.parseString(string).asDict()
      print parsedict
      command = "cmd_" + parsedict["verb"]
   except:
      print "Not in grammar->",string
      command = "cmd_unknown"
      parsedict = {}

   #Try and get the implementaion of the command, this may fail due to not having been implemented yet.
   try:
      action = getattr(Commands,command)
   except:
      print "Not implemented->",command
      action = getattr(Commands,"cmd_notimp")
      
   return action,parsedict

